﻿<%@ Page Language="C#" %>
<%@ Import Namespace="IRL.Utilities" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">    
    public const int CURRENT_MODULE = 52;
    
    AutoNum seq = new AutoNum();
    SqlConnection conn;
    bool HasWriteAccess = false;
        
    string clientID, clientName, Sector, Country;
    
    protected void Page_Load(object src, EventArgs e)
    {
        Security SysAcc = new Security(CURRENT_MODULE);
        // check is authenticate
        SysAcc.Authenticate();
        HasWriteAccess = SysAcc.IsAuthorized(2);
        
        // load reminder count        
        Mics.loadReminderCount(lblReminderCount);
        
        object connStr = ConfigurationSettings.AppSettings["sqlConn"];        
        if (connStr == null)
            Response.Redirect("unavailable.htm");
        else
        {
            conn = new SqlConnection(connStr.ToString());

            clientID = Request.QueryString["cid"];

            if (clientID == null)
                Response.Redirect("listClients.aspx");
            else
            {                
                if (!Page.IsPostBack)
                {
                    //sortFld = "ClientName";
                    CompanyInfo();
                    rebind();
                    if (!HasWriteAccess)
                    {
                        EditButton.Visible = false;
                    }
                }
            }
        }
    }

    // bind to datagrid
    void rebind()
    {
        //Response.Write("SELECT ContactID, ClientID, Title+'. '+FirstName+' '+LastName AS [FullName], JobTitle, OfficePhone, Mobile, Email FROM cms_Contacts WHERE [ClientID]=" + clientID); Response.End();
        SqlDataAdapter adapter = new SqlDataAdapter
            (
                "SELECT Contact_ID, Company_ID, Title+'. '+FirstName+' '+LastName AS [FullName], JobTitle, Mobile, Email_Address FROM tbl_Contact_Person WHERE [Company_ID]="+ clientID +";", 
                conn
            );
        
        DataSet ds = new DataSet();        
        DataView dv;
        adapter.Fill(ds, "Contacts");
        // Reset AutoNum
        seq.Reset();
        // Bind to Grid
        dv = ds.Tables[0].DefaultView;        
        gridContacts.DataSource = dv;
        gridContacts.DataBind();
    }

    void CompanyInfo()
    {
        SqlCommand cmd = new SqlCommand("SELECT [Company_ID], [Company_Name], [Sector], [Country] FROM [vw_Clients] WHERE [Company_ID]=" + clientID, conn);
        if (conn.State == ConnectionState.Closed)
            conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            clientName = dr["Company_Name"].ToString();
            Sector = dr["Sector"].ToString();
            Country = dr["Country"].ToString();
        }
        else
        {
            Response.Redirect("listClients.aspx");
        }
        dr.Close();
        
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="Description" content="Providing the tools and expertise needed to navigate in the emerging consumer markets of Indochina.">
    <meta name="keywords" content="Research in Indochina, Research Consultants in Indochina, Marketing Research in Indochina, Marketing Research Companies in Indochina, Marketing Consultants in Indochina Research in Vietnam, Research Consultants in Vietnam, Marketing Research in Vietnam, Marketing Research Companies in Vietnam, Marketing Consultants in Vietnam Research in Cambodia, Research Consultants in Cambodia, Marketing Research in Cambodia, Marketing Research Companies in Cambodia, Marketing Consultants in Cambodia Research in Laos, Research Consultants in Laos, Marketing Research in Laos, Marketing Research Companies in Laos, Marketing Consultants in Laos">
    <meta name="robots" content="all">

    <title>CMS - Client contact</title>
    <link type="text/css" rel="stylesheet" href="css/style_1.css" />
    <script language="javascript" src="includes/menustructure.js"></script>

</head>

<body>
<table width="773" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td width="765" height="540" align="center" valign="top" style="border:solid 1px #10147e;" >
			<!-- header -->
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr bgcolor="#F4F4F9">
					<td colspan="3" align="right" style="padding:10px;">
						<b class="blueL">Client Management System</b>
					</td>
				</tr>
				<tr>
					<td class="wave_l">
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
						      <tr class="menu">
							  	<td><a class="dropdown" onMouseOver="dropdownmenu(this, event, menu1,'160px')" onMouseOut="delayhidemenu()">Project Management</a></td>
							    <td><a href="listClients.aspx">Clients &amp; Contacts</a></td>
							  </tr>
						</table></td>
					<td><img src="images/wave_logo.jpg" width="107" height="83"></td>
					<td class="wave_r">
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
						      <tr class="menu">
							  	<td><a href="ops_Proposals.aspx">Ops files</a></td>
							    <td align="center"><a class="dropdown" onMouseOver="dropdownmenu(this, event, menu2, '160px')" onMouseOut="delayhidemenu()">Reminders <asp:Literal ID="lblReminderCount" runat="server" /></a></td>
                                <td align="right"><a href="javascript:window.close();">Close</a></td>
							  </tr>
						</table></td>
				</tr>
				<tr>
					<td colspan="3" style="padding:0 20px;">
						<div style="background-color:#bcb3d5; padding:5px 10px;">
							<span style="float:right">
								<a class="blue" href="saveClient.aspx">Add New Client*</a></span>
							<span class="pathmap">
								<a href="default.aspx" >CPanel</a> :: 
                                <a href="listClients.aspx">Clients</a> :: Contacts
								</span>
						</div>
						
					</td>
				</tr>
				
			</table>
			
			<!-- body -->
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center" style="padding:20px;">
						<!-- company info -->
                        <table border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td style="width: 39px">
                                    <img src="images/spacer.gif" width="39" height="1" /></td>
                                <td>
                                    <table border="0" cellspacing="0" cellpadding="8" style="font-size: 7.5pt;">
                                        <tr>
                                            <td>
                                                <b class="gray">Company:</b></td>
                                            <td width="12">
                                                &nbsp;</td>
                                            <td>
                                                <b class="blueL">
                                                    <%=clientName %>
                                                </b>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <b class="gray">Operational Sector:</b></td>
                                            <td width="12">
                                                &nbsp;</td>
                                            <td>
                                                <b class="blueL">
                                                    <%=Sector %>
                                                </b>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <b class="gray">Region:</b></td>
                                            <td width="12">
                                                &nbsp;</td>
                                            <td>
                                                <b class="blueL">
                                                    <%=Country %>
                                                </b>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="80">
                                    <img src="images/spacer.gif" width="80" height="1" /></td>
                                <td>
                                    <table id="EditButton" border="0" cellpadding="2" cellspacing="0" runat="server">
                                        <tr>
                                            <td width="120">
                                                <a class="cmd" href="saveContact.aspx?oid=<%=clientID %>">Add a person</a></td>
                                        </tr>
                                        <tr>
                                            <td width="120">
                                                <a class="cmd" href="saveClient.aspx?cid=<%=clientID %>">Update Company</a></td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="39">
                                    <img src="images/spacer.gif" width="39" height="1" /></td>
                            </tr>
                        </table>
                        <!-- contact list -->
                        <table class="data" width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td>
                                    &nbsp;</td>
                            </tr>
                            <tr>
                                <td>
                                    <!-- data row -->
                                    <div>
                                        <!-- style="overflow-x:auto; width:840px"-->
                                        <form id="frmClients" runat="server">
                                            <asp:DataGrid ID="gridContacts" Width="100%" runat="server" CellSpacing="1" CellPadding="4"
                                                BorderWidth="0" GridLines="none" AutoGenerateColumns="false">
                                                <HeaderStyle Height="16" BackColor="#bcb3d5" Font-Size="7.5pt" ForeColor="white"
                                                    Font-Bold="true" />
                                                <AlternatingItemStyle BackColor="#efefef" />
                                                <Columns>
                                                    <asp:TemplateColumn HeaderText="No">
                                                        <HeaderStyle Width="20" />
                                                        <ItemTemplate>
                                                            <%# seq.GetNext()%>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                    <asp:TemplateColumn HeaderText="Fullname" SortExpression="FullName">
                                                        <HeaderStyle Width="180" />
                                                        <ItemTemplate>
                                                            <b><a href="saveContact.aspx?oid=<%=clientID %>&cid=<%# DataBinder.Eval(Container.DataItem, "Contact_ID") %>">
                                                                <%# DataBinder.Eval(Container.DataItem, "FullName")%>
                                                            </a></b>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                    <asp:TemplateColumn HeaderText="Job Title" SortExpression="JobTitle">
                                                        <HeaderStyle Width="200" />
                                                        <ItemTemplate>
                                                            <%# DataBinder.Eval(Container.DataItem, "JobTitle")%>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                    <asp:TemplateColumn HeaderText="Mobile" SortExpression="Mobile">
                                                        <HeaderStyle Width="80" />
                                                        <ItemTemplate>
                                                            <%# DataBinder.Eval(Container.DataItem, "Mobile")%>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                    <asp:TemplateColumn HeaderText="Email" SortExpression="Email_Address">
                                                        <HeaderStyle Width="180" />
                                                        <ItemTemplate>
                                                            <a href="mailto:<%# DataBinder.Eval(Container.DataItem, "Email_Address")%>">
                                                                <%# DataBinder.Eval(Container.DataItem, "Email_Address")%>
                                                            </a>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                </Columns>
                                            </asp:DataGrid>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        </table>
					</td>
				</tr>
			</table>
			
		</td>
		
		<td width="6" class="rightShadow" valign="top">
			<img src="images/white.gif" width="6" height="6" /></td>
	</tr>
	
	<!-- bottom shadow -->
	<tr>
		<td height="6" class="bottomShadow">
			<img src="images/white.gif" width="6" height="6" /></td>
		
		<td width="6" height="6">
			<img src="images/shadow_corner.gif" width="6" height="6" /></td>
	</tr>
</table>

</body>
</html>
